package com.example.security.web;

import com.example.security.domain.User;
import com.example.security.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.example.security.utils.Constants.SUCCESS_MAP;

@RestController
@RequiredArgsConstructor
@RequestMapping("user")
public class UserController {



    private final UserService userService;


    @GetMapping
    public PageInfo<User> list(@RequestParam(defaultValue = "1") int pageSize, @RequestParam(defaultValue = "10") int pageNum, User user) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> userList = userService.queryUserList(user);
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        return pageInfo;
    }

    @PostMapping
    public Map<String, Object> create(@RequestBody User user) {
        userService.create(user);
        return SUCCESS_MAP;
    }

    @PutMapping
    public Map<String, Object> modify(@RequestBody User user) {
        userService.modify(user);
        return SUCCESS_MAP;
    }


    @DeleteMapping
    public Map<String, Object> remove(List<Integer> keys) {
        userService.remove(keys);
        return SUCCESS_MAP;
    }













}
